package com.isunland.managesystem.ui;

import android.os.Bundle;
import android.view.View;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.isunland.managesystem.adapter.SignDeliveryAdapter;
import com.isunland.managesystem.base.BaseListFragment;
import com.isunland.managesystem.base.BaseOriginal;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.RDistributionSub;
import com.isunland.managesystem.entity.rDistributionMain;
import com.isunland.managesystem.utils.ParamsNotEmpty;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/7/21 10:56
 */
public class SignDeliveryListFragment extends BaseListFragment {
  private ArrayList<RDistributionSub> mList;
  private SignDeliveryAdapter mAdapter;
  private rDistributionMain mItemMain;

  @Override public void initData() {
    super.initData();
    mItemMain = mBaseParams.getItem() instanceof rDistributionMain ? (rDistributionMain) mBaseParams
        .getItem() : new rDistributionMain();
    mList = new ArrayList<>();
    mAdapter = new SignDeliveryAdapter(mActivity, mList);
  }

  @Override public void initView(View view, Bundle savedInstanceState) {
    super.initView(view, savedInstanceState);
    setListAdapter(mAdapter);
  }

  @Override public String getUrl() {
    return ApiConst.URL_QUERY_LIST_SIGN_DELIVERY;
  }

  @Override public HashMap<String, String> getparameters() {
    ParamsNotEmpty params = new ParamsNotEmpty();
    params.put("mainId", mItemMain.getId());
    return params.getParams();
  }

  @Override public void resolveResponse(String json) {
    BaseOriginal<RDistributionSub> original =
        new Gson().fromJson(json, new TypeToken<BaseOriginal<RDistributionSub>>() {
        }.getType());
    mList.clear();
    mList.addAll(original.getRows());
    mAdapter.notifyDataSetChanged();
  }
}
